package com.lxl.bt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.lxl.bt.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * 兑换记录
 */

public class OrderItemAdapter extends RecyclerView.Adapter<OrderItemAdapter.BoxViewHolder> {



    private List<Object> datas;
    private OnItemClickListener onItemClickListener;

    public OrderItemAdapter(List<Object> datas, OnItemClickListener onItemClickListener) {
        this.datas = datas;
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public BoxViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_orderitem, parent, false);
        BoxViewHolder viewHolder = new BoxViewHolder(root);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(BoxViewHolder holder, int position) {
        Context mContext = holder.mContext;
        holder.tvDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemDetail(v, position);
            }
        });
    }


    public Object getItem(int position) {

        return datas.get(position);
    }


    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public void setDatas(List<Object> comments) {
        this.datas = comments;
        notifyDataSetChanged();
    }

    public static class BoxViewHolder extends RecyclerView.ViewHolder {


        public Context mContext;
        @BindView(R.id.tvName)
        TextView tvName;
        @BindView(R.id.tvTime)
        TextView tvTime;
        @BindView(R.id.tvStatus)
        TextView tvStatus;
        @BindView(R.id.tvDes)
        TextView tvDes;
        @BindView(R.id.tv10)
        TextView tv10;
        @BindView(R.id.tvT1)
        TextView tvT1;
        @BindView(R.id.tvLeiji)
        TextView tvLeiji;
        @BindView(R.id.tvZt)
        TextView tvZt;
        @BindView(R.id.tvEndDay)
        TextView tvEndDay;
        @BindView(R.id.tvEndTime)
        TextView tvEndTime;
        @BindView(R.id.tvDetail)
        TextView tvDetail;

        public BoxViewHolder(View itemView) {
            super(itemView);
            mContext = itemView.getContext();
            ButterKnife.bind(this, itemView);


        }
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    public interface OnItemClickListener {
        void onItemDetail(View view, int position);

    }


}
